package me.blog.markan.android.desktop.web;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Hashtable;
import java.util.Iterator;

public class HttpWebReponse {
	private String httpResCode = "200 OK";
	private Hashtable<String, String> htAttrs = null;
	private OutputStream os = null;
	
	public void writeStringToHeader() throws IOException {
		String header = getRawHeaderText();
		this.os.write(header.getBytes(), 0, header.length());
	}
	
	public HttpWebReponse(OutputStream os) {
		this.os = os;
	}
	
	public OutputStream getOutputStream() {
		return this.os;
	}
	
	public String getRawHeaderText() {
		StringBuffer retStr = new StringBuffer("HTTP/1.0 " + this.httpResCode + "\n");
		if (this.htAttrs != null) {
			Iterator keys = this.htAttrs.keySet().iterator();
			while (keys.hasNext()) {
				String key = (String)keys.next();
				retStr.append(key + " : " + (String)this.htAttrs.get(key) + "\n");
			}
		}
		retStr.append("\n");
	
		return retStr.toString();
	}

	public void write(byte[] bytes) throws IOException {
		os.write(bytes);
	}
}
